<template>
  <div class="mobile-login-page">
    <el-card class="login-card">
      <h2 class="login-title">配送员登录</h2>
      <el-form :model="loginForm" @submit.native.prevent="handleLogin">
        <el-form-item>
          <el-input v-model="loginForm.username" placeholder="请输入手机号/工号" clearable />
        </el-form-item>
        <el-form-item>
          <el-input v-model="loginForm.password" type="password" placeholder="请输入密码" clearable show-password />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" style="width:100%;" @click="handleLogin" :loading="loading">登录</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import { ElMessage } from 'element-plus'
// 你需要实现 mobileLogin 这个API
// import { mobileLogin } from '@/assets/delivery.js'

const router = useRouter()
const route = useRoute()
const loading = ref(false)
const loginForm = ref({
  username: '',
  password: ''
})

const handleLogin = async () => {
  if (!loginForm.value.username || !loginForm.value.password) {
    ElMessage.warning('请输入账号和密码')
    return
  }
  loading.value = true
  try {
    const res = await mobileLogin(loginForm.value)
    if (res.data.code === 200) {
      localStorage.setItem('token', res.data.data.token)
      ElMessage.success('登录成功')
      const redirect = route.query.redirect || '/mobile/confirm'
      router.replace(redirect)
    } else {
      ElMessage.error(res.data.message || '登录失败')
    }
  } catch (e) {
    ElMessage.error('网络错误')
  } finally {
    loading.value = false
  }
}
</script>

<style scoped>
.mobile-login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f7f8fa;
}
.login-card {
  width: 90vw;
  max-width: 350px;
  margin: 0 auto;
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.06);
}
.login-title {
  text-align: center;
  margin-bottom: 24px;
  font-size: 22px;
  font-weight: bold;
  color: #333;
}
</style> 